home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-15 / uartty12.zip / UARTTYPE.ASM < prev    next >
Assembly Source File  |  1992-05-30  |  6KB  |  191 lines

  1. title "UART Detector"
  2. UART_DET  segment para public 'code'
  3.         assume  cs:UART_DET, ds:UART_DET, es:UART_DET
  4. page 60, 132
  5.  
  6. ; comments -- the WRITE function is left up to your own implementation
  7. ; v1.1 Toad Hall Tweak, May 91
  8. ;        Yeah, well, we can do that.
  9. ;        David Kirschbaum
  10. ;        Toad Hall
  11. ;        kirsch%maxemail@uunet
  12. ; v1.2 wvl tweak, May 92
  13. ;        Heck, we can even check all the comm ports, not just the one 
  14. ;        which is hard coded and display the port base address, too.
  15. ;        William Luitje
  16. ;        luitje@m-net.ann-arbor.mi.us
  17.  
  18. ; constants
  19.  
  20. BIOSdseg equ    40h          ; data segment for BIOS
  21. IIR      equ    2            ;Interrupt Indentification Register offset
  22.  
  23.          .model tiny           ; tiny model (.COM)
  24.          .code
  25.          org    100h           ; .COM files start at 100h
  26.  
  27. entry:
  28.          jmp    start          ; jump to start of progarm
  29.  
  30. ; variables
  31.  
  32. _UARTbase       dw      ?    ;UART base address
  33. xbyte2          db      ?
  34.  
  35. jmp_table   dw      uart_8250_or_16450, uart_unknown, uart_16550, uart_16550a
  36. banner          db      'UART Detector, Version 1.2',0ah,0dh
  37.                 db      'Comm Base Adr Type',0ah,0dh,'$'
  38. type_msg        db      '  '
  39. portno          db      'x   $'
  40. base_msg        db      ' xxxx   $'
  41. notinst         db      'Not Installed',0ah,0dh,'$'
  42. m8250           db     '8250',0ah,0dh,'$'
  43. m16450          db     '16450',0ah,0dh,'$'
  44. munknown        db     'Unknown (possibly 82510)',0ah,0dh,'$'
  45. m16550          db     '16550',0ah,0dh,'$'
  46. m16550a         db     '16550A',0ah,0dh,'$'
  47. HexTbl          db     '0123456789ABCDEF'
  48.  
  49. ; ------------------------ MAIN ------------------------------
  50.  
  51. start    proc
  52. ;-Display banner
  53.         mov     dx,offset banner
  54.          call   Display
  55.          mov    ax, BIOSdseg
  56.          mov    es, ax         ; move bios data segment into ES
  57. ;-For (cx = 0; cx<4; ++cx)
  58.          xor    cx,cx
  59. ;---Find & display UART type
  60. start1:  call   findType
  61.          inc    cx
  62.          cmp    cx,4
  63.          jne    start1
  64. ;-End For
  65. ;-Exit
  66.          mov    ax, 4c00h     ;terminate
  67.          int    21h
  68.  
  69. ;------------Find UART type for a given comm port-------------
  70. ; CX:  Comm port # -1
  71. findType:
  72.          push   cx
  73. ;-Display port number
  74.          mov    al,cl
  75.          add    al,031h
  76.         mov     portno,al
  77.         mov     dx,offset type_msg
  78.          call   Display
  79. ;-Get Requested Port Base Address
  80.          shl    cx,1
  81.          mov    bx,cx
  82.         mov     dx,es:[bx]      ; get offset for serial port
  83.         mov     _UARTbase,dx    ; _UARTbase := serial port base address
  84. ;-Display Base Address 
  85.          call   Hex2Asc
  86.          mov    dx,offset base_msg
  87.          call   Display
  88.          mov    dx,_UARTBASE
  89. ;-If base address == 0
  90.         test    dx,0ffffh
  91.         jne     find1           ;no, cool
  92. ;---Display "Not installed"
  93.          mov    dx,offset notinst
  94.          call   Display
  95.          jmp    findret
  96. ;-Else
  97. ;---Figure out which type IS installed
  98. find1:
  99.          mov    dx,_UARTbase
  100.          add    dx,IIR
  101.          in     al, dx         ; al := port [dx]
  102.          mov    xbyte2, al    ; xbyte2 := al
  103.          mov    al, 0c1h      ; al := $C1
  104.          out    dx, al         ; port [dx] := al
  105.          in     al, dx         ; al := port [dx]
  106.          and    al, 0c0h      ; al := (al AND $C0)
  107.          mov    cl, 5          ; cl := 5
  108.          shr    al, cl         ; al := (al shr 5) (5 for word jmp)
  109.          xor    ah,ah          ; ah := 0   v1.1
  110.          mov    bp, ax         ; bp := ax (al)
  111.          mov    al, xbyte2    ; al := xbyte2
  112.          out    dx, al         ; port [dx] := al
  113.          jmp    CS:[jmp_table+bp] ;    v1.1
  114.  
  115. uart_8250_or_16450:
  116.          mov    dx, _UARTbase  ; dx := _UARTbase
  117.          add    dx, 7          ; dx := dx + 7
  118.          in     al, dx         ; al := port [dx]
  119.          mov    xbyte2, al    ; xbyte2 := al
  120.          mov    al, 0fah      ; al := $FA
  121.          out    dx, al         ; port [dx] := al
  122.          in     al, dx         ; al := port [dx]
  123.          cmp    al, 0fah      ; if (al <> $FA)
  124.          jne    uart_16450    ; then uart is 16450
  125.          mov    al, 0afh      ; al := $AF
  126.          out    dx, al         ; port [dx] := al
  127.          in     al, dx         ; al := port [dx]
  128.          cmp    al, 0afh      ; if (al <> $AF)
  129.          jne    uart_8250     ; then uart is 8250
  130.          mov    al, xbyte2    ; else al := xbyte2
  131.          out    dx, al         ; port [dx] := al
  132.          jmp    short uart_16450 ; uart is 16450
  133.  
  134. uart_8250:
  135.          mov    dx,offset m8250
  136.          call   Display
  137.          jmp    findret
  138.  
  139. uart_16450:
  140.          mov    dx,offset m16450
  141.          call   Display
  142.          jmp    findret
  143.  
  144. uart_unknown:
  145.          mov    dx,offset munknown
  146.          call   Display
  147.          jmp    findret
  148.  
  149. uart_16550:
  150.          mov    dx,offset m16550
  151.          call   Display
  152.          jmp    findret
  153.  
  154. uart_16550a:
  155.          mov    dx,offset m16550a
  156.          call   Display
  157. findret: pop    cx
  158.          ret
  159.  
  160. Display:
  161.          mov    ah,09h         ;display msg in DX  v1.1
  162.          int    21H            ;via DOS   v1.1
  163.          ret
  164. Hex2Asc:
  165.          xor    bl,bl
  166.          mov    bl,dh                  ;display high nibble of dh
  167.          mov    cl,4
  168.          shr    bl,cl
  169.          mov    al,byte ptr HexTbl[bx]
  170.          mov    base_msg+1,al
  171.          mov    bl,dh                  ;display low nibble of dh
  172.          and    bl,0fH
  173.          mov    al,HexTbl[bx]
  174.          mov    base_msg+2,al
  175.          mov    bl,dl                  ;display high nibble of dl
  176.          mov    cl,4
  177.          shr    bl,cl
  178.          mov    al,HexTbl[bx]
  179.          mov    base_msg+3,al
  180.          mov    bl,dl                  ;display low nibble of dl
  181.          and    bl,0fH
  182.          mov    al,HexTbl[bx]
  183.          mov    base_msg+4,al
  184.          ret
  185.  
  186. start    endp                  ; end of proc
  187.  
  188. END      entry                 ; end of program
  189. UART_DET  ends
  190. 
  191.